<!--suppress ALL -->
<template>
    <div class="page" data-page="mine" style="z-index: 2;">
        <div class="page-content mine-page ptr-content" @ptr:refresh="refreshCurrent">
            <div class="ptr-preloader" id="refresh_mine">
                <div class="preloader color-multi"></div>
                <div class="ptr-arrow"></div>
            </div>
            <div class="list links-list top-list">
                <ul>
                    <li>
                        <a href="/mineMsg/" class="link" data-view=".view-main">
                            <div style="width: 60px;height: 60px;">
                                <img src="{{staticPath}}img/mine/defaulticon.png" class="myicon_mine">
                            </div>
                            <div class="mine_msg_div">
                                <p class="mine_name"></p>
                                <p class="mine_role"></p>
                            </div>
                        </a>
                    </li>
                </ul>
            </div>
            <div class="list links-list" style="padding: 0;">
                <div class="mine-margin">
                    <i class="icon iconfont icon-APPicon_guanzhu" style="color:#F02020;margin-right:6px"></i>
                    <span class="tt">我的关注</span>
                </div>
                <ul id="followCountList">
                    <li class="focus-permiss_mine" data-link="keyIssuesList">
                        <a href="/mineFocunsOn/0/1/" class="mine-item-content" data-view=".view-main">
                            <div class="item-media">
                                <div class="item-media-icon redC" style="background-color: #ffc73b">
                                    <i class="iconfont icon-APPgongzuotaileixingtubiao_zhongdianwenti"></i>
                                </div>
                            </div>
                            <div class="item-inner mine-item-inner">
                                <div class="item-title"></div>
                                <div class="item-after">0</div>
                            </div>
                        </a>
                    </li>

                    <li class="focus-permiss_mine" data-link="moreDectorState">
                        <a href="/mineFocunsOn/0/3/" class="mine-item-content" data-view=".view-main">
                            <div class="item-media">
                                <div class="item-media-icon blueC">
                                    <i class="iconfont icon-APPgongzuotaileixingtubiao_zichan"></i>
                                </div>
                            </div>
                            <div class="item-inner mine-item-inner">
                                <div class="item-title"></div>
                                <div class="item-after">0</div>
                            </div>
                        </a>
                    </li>

                    <li class="focus-permiss_mine" data-link="troubleApply">
                        <a href="/mineFocunsOn/0/4/" class="mine-item-content" data-view=".view-main">
                            <div class="item-media">
                                <div class="item-media-icon greenC">
                                    <i class="iconfont icon-APPgongzuotaileixingtubiao_yinhuanzhenggai"></i>
                                </div>
                            </div>
                            <div class="item-inner mine-item-inner">
                                <div class="item-title"></div>
                                <div class="item-after">0</div>
                            </div>
                        </a>
                    </li>

                    <li>
                        <a href="/mineFocunsOn/0/5/" class="mine-item-content" data-view=".view-main">
                            <div class="item-media">
                                <div class="item-media-icon yellowC">
                                    <i class="iconfont icon-APP_shipin-xian"></i>
                                </div>
                            </div>
                            <div class="item-inner mine-item-inner">
                                <div class="item-title">监控</div>
                                <div class="item-after">0</div>
                            </div>
                        </a>
                    </li>

                    <li>
                        <a href="/subscribe/" class="mine-item-content" data-view=".view-main">
                            <div class="item-media">
                                <div class="item-media-icon redC" style="background-color: #ffc73b">
                                    <i class="iconfont icon-APPgongzuotaileixingtubiao_jiechujing"></i>
                                </div>
                            </div>
                            <div class="item-inner mine-item-inner">
                                <div class="item-title">警情订阅</div>
                            </div>
                        </a>
                    </li>

                </ul>
                <div class="mine-margin" style="margin-top:27px">
                    <span class="tt">小助手</span>
                </div>

                <ul>
                    <li @click="offlineModel" id="offline_view">
                        <a href="#" style="padding: 0">
                            <div class="item-inner" style="padding: 0">
                                <div class="item-title mine-margin" id="offlineModel_id">离线作业</div>
                                <div class="item-after"></div>
                            </div>
                        </a>
                    </li>
                    <li @click="updateEd">
                        <a href="#" style="padding:0">
                            <div class="item-inner">
                                <div class="item-title mine-margin">检查更新</div>
                                <div class="item-after " id="versionText" style="color:#999;margin-right:12px"></div>
                            </div>
                        </a>
                    </li>
                    <li @click="clear_cache_fn">
                        <a href="#" style="padding: 0">
                            <div class="item-inner">
                                <div class="item-title mine-margin">清除缓存</div>
                                <div class="item-after" style="color:#999;margin-right:12px">遇到无法处理的问题时，点这里</div>
                            </div>
                        </a>
                    </li>
                    <li class="border-bottom-mine2"></li>
                    <li @click="shareReport" id="isShare">
                        <a href="#" style="padding: 0">
                            <div class="item-inner" style="padding: 0">
                                <div class="item-title mine-margin">立即分享</div>
                                <div class="item-after"></div>
                            </div>
                        </a>
                    </li>
                </ul>
            </div>
            <div class="mine-item-content">
                <a href="#" class="mine-loginout" @click="backLogin">退出登录</a>
            </div>
        </div>

        <div id="subScribePopup" class="popup">
            <div></div>
        </div>

    </div>
</template>
<script>
    return {
        data: function () {
            return {
                status: 0, //离岗
                androidUrl: '',
                iosUrl: '',
            }
        },
        methods: {
            backToRefresh: function () {
                let self = this;
                self.getMyFocusStatus();
                self.getUserInforMine()
            },
            offlineModel: function () {
                var IS_OFFLINE_MODULE = native.getDataByKey("IS_OFFLINE_MODULE");
                if (IS_OFFLINE_MODULE != "1") {
                    app.router.navigate("/selectofflineWork/");
                } else {
                    app.methods.showToastBottom('离线作业已关闭');
                    native.saveDataByKey("IS_OFFLINE_MODULE", 0)
                }
            },
            shareReport: function () {
                let self = this;
                var u = navigator.userAgent;
                var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
                var isIOS = u.indexOf('iPhone') > -1 || u.indexOf('iPad') > -1; //IOS终端
                if ((isAndroid && !self.androidUrl) || (isIOS && !self.iosUrl)) {
                    app.methods.showToastCenter('未获取安装包');
                } else {
                    let logoUrl = REMOTESTATICPATH + platformCode + "/pc/login/logo/logo.png";
                    native.shareReport('http://47.96.25.44:8281/ilink-app-h5-zd/' + "pages/share.html?iosUrl=" +
                        self.iosUrl + "&androidUrl=" + self.androidUrl + "&logoUrl=" + logoUrl, '', '',
                        'noEmail');
                }
            },
            //用户信息
            getUserInforMine() {
                var self = this;
                //基本信息
                $(".mine_name").html(common.transNullundefinedToline(userInfor.name));
                $(".mine_role").html(common.transNullundefinedToline(userInfor.org.name));
                if (userInfor.headUrl && userInfor.headUrl.length > 0) {
                    $(".myicon_mine").show();
                    $(".myicon_mine").attr("src", userInfor.headUrl);
                }
            },
            //我的关注统计
            getMyFocusStatus: function () {
                var self = this;
                Dao.statisticsUserConcem_ajax({
                    userAccount: userInfor.accountName
                }, function (data) {
                    var listItem = $("#followCountList li .item-after");
                    //在赋值前全部清空
                    for (var i = 0; i < listItem.length; i++) {
                        $(listItem[i]).html(0);
                    }
                    // 1:设施监测, 2:视频, 3:重大问题, 4:接处警, 5:隐患整改 (仅提供有关注数量的)
                    if (data && data.length > 0) {
                        for (var i = 0; i < data.length; i++) {
                            if (data[i].type == "1") { // 1:设施监测
                                $(listItem[1]).html(data[i].count);
                            }
                            if (data[i].type == "2") { //2:视频
                                $(listItem[3]).html(data[i].count);
                            }
                            if (data[i].type == "3") { //3:重大问题
                                $(listItem[0]).html(data[i].count);
                            }
                            // if(data[i].type=="4"){//4:接处警
                            // 	$(listItem[1]).html(data[i].count);
                            // }
                            if (data[i].type == "5") { //5:隐患整改
                                $(listItem[2]).html(data[i].count);
                            }
                        }
                    }
                });
            },
            clear_cache_fn: function () {
                native.clear_cache();
                native.addJsFile();
                app.methods.showToastCenter('清除完成');
            },
            unitInfo: function () {
                if (userInfor.isMuilUnitUser == 0) { // 单
                    app.router.navigate("/unitInfo/" + userInfor.org.id + "/");
                } else {
                    app.router.navigate("/unitList/"); //多
                }
            },
            clickChangeDutyStatus: function () {
                var self = this;
                //原本是在岗
                if (self.status == 1) {
                    self.status = 0;
                } else {
                    self.status = 1;
                }
                self.changeOnline();
            },
            changeDutyStatus: function () {
                var self = this;
                //原本是在岗
                if (self.status == 0) {
                    jQuery(".duty-btn").css({
                        "background-color": "#e1e1e1",
                        "color": "#3e8ffd",
                        "border": "1px solid #3e8ffd"
                    }).html("离岗中，点击签到");
                } else {
                    jQuery(".duty-btn").css({
                        "background-color": "#3e8ffd",
                        "color": "#fff",
                        "border": "none"
                    }).html("在岗中，点击签退");
                }
            },
            //获取在岗情况
            getOnlineInfo: function () {
                var self = this;
                common.loading(1);
                Dao.getOnlineInfo({
                    userName: userInfor.accountName,
                    deviceId: appKeyObj.deviceId,
                }, function (data) {
                    if (undefined !== data || null !== data) {
                        if (data == 1) {
                            self.status = 1;
                        } else if (data == null || data == 0) {
                            self.status = 0;
                        }
                        self.changeDutyStatus();
                    }
                    common.loading(0);
                }, function (e) {
                    common.loading(0);
                    app.methods.showToastBottom('获取值班状态失败');
                });
            },
            //在岗  离岗
            changeOnline: function () {
                var self = this;
                var online = null;
                if (self.status == 1) {
                    online = 1;
                } else {
                    online = 0;
                }
                common.loading(1);
                Dao.changeOnline({
                    userName: userInfor.accountName,
                    deviceId: appKeyObj.deviceId,
                    online: online,
                }, function (data) {
                    common.loading(0);
                    self.changeDutyStatus();

                }, false);
            },
            //二维码code-row
            showCode: function () {
                var self = this;
                Dao.getNewAppV({
                    organizationId: platformCodeId,
                    type: 1
                }, function (data) {
                    if (data) {
                        self.iosUrl = data.url;
                    }
                });
                Dao.getNewAppV({
                    organizationId: platformCodeId,
                    type: 2
                }, function (data) {
                    if (data) {
                        self.androidUrl = data.url;
                    }
                });
            },
            backLogin: function () {
                common.loading(1);
                // 退出登录
                Dao.userlodOut({
                    userId: userInfor.id
                }, function (res) {

                });
                setTimeout(native.logOut(), 2000);
            },
            isShowMyFocus: function () {
                var applyArr = jQuery(".focus-permiss_mine");
                if (userInfor.resources.length > 0) {
                    for (var i = 0; i < userInfor.resources.length; i++) {
                        for (var n = 0; n < applyArr.length; n++) {
                            let link = jQuery(applyArr[n]).attr("data-link");
                            if (link.indexOf(userInfor.resources[i].link) > -1) {
                                jQuery(applyArr[n]).children().find(".item-title").html(userInfor.resources[i]
                                    .resourceName);
                                jQuery(applyArr[n]).show();
                            }
                        }
                    }
                }
            },
            refreshCurrent: function (e, done) {
                var self = this;
                var $ = self.$$;
                if (1 === e) {
                    common.loading(1);
                }
                if (done && e) {
                    setTimeout(function () {
                        //统计
                        self.getMyFocusStatus();
                        self.getUserInforMine();
                        done();
                        if (1 === e) {
                            common.loading(0);
                        }
                    }, 1000);
                }
            },
            //版本更新
            updateEd: function () {
                if (!getClickEnabel()) return
                native.checkVersion()
            },
        },
        on: {
            pageInit: function (e, page) {
                var self = this;
                //在岗情况
                for (var i = 0; i < userInfor.role.length; i++) {
                    //根据一般用户才显示，其余隐藏
                    if (userInfor.role[i].id == 144) {
                        $(".duty-btn").show();
                        self.getOnlineInfo();
                        break;
                    } else {
                        $(".duty-btn").hide();
                    }
                }
                //二维码
                self.showCode();

                //单位信息
                if (userInfor.isMuilUnitUser == 0) {
                    jQuery("#unitInfo-mes").show();
                    jQuery("#duty_li").show();
                } else {
                    jQuery("#unitInfo-mes").show();
                    jQuery("#duty_li").hide();
                }
                //九小用户
                if (userInfor.role[0].id == 143) {
                    $("#isNine").hide();
                } else {
                    $("#isNine").show();
                }

                //用户信息
                self.getUserInforMine();
                //统计
                self.getMyFocusStatus();
                //我的关注列表权限控制
                self.isShowMyFocus();

                // 一体机没有离线作业和分享
                if(QINIUPATH==='/ilink-file/'){
                    $("#isShare").hide();
                }

                //版本更新判断
                var u = navigator.userAgent;
                var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
                var isIOS = u.indexOf('iPhone') > -1 || u.indexOf('iPad') > -1; //IOS终端
                var type = isAndroid ? 2 : (isIOS ? 1 : 0);
                Dao.findOrgByOrgCode({
                    userName: userInfor.accountName,
                    deviceId: appKeyObj.deviceId,
                    orgCode: platformCode || app.data.defaultPlatCode
                }, function (re) {
                    Dao.checkVersion({
                        userName: userInfor.accountName,
                        deviceId: appKeyObj.deviceId,
                        organizationId: re,
                        type: type,
                        isCustom: 1,
                    }, function (data) {
                        if (data) {
                            var versionCode = native.getVersion();
                            if (isIOS) {
                                versionCode = native.getIOSVersion();
                            }
                            if (versionCode < data.softNumber) {
                                $("#versionText").html("立即更新到最新版本")
                                $("#versionText").css("color", "red")
                            } else {
                                $("#versionText").html("已是最新版本")
                            }
                        }
                    });
                }, null, function (res) {});
                if (isIOS) {
                    document.getElementById("offline_view").style.display = "none";
                }
            }
        }

    }
</script>
<style scoped>
    #unitInfo-mes {
        display: none;
    }

    .mine-page {
        position: relative;
    }

    .code-row {
        width: 88%;
        margin: auto;
        text-align: center;
        margin-top: 20%;
    }

    .mine-page .links-list a:after {
        height: 0;
    }

    .mine-page .list ul:before {
        height: 0;
    }

    .mine-page .list ul:after {
        height: 0;
    }

    .mine-page .list .item-inner:after {
        height: 0;
    }

    .mine-page-line {
        width: 100%;
        height: 10px;
        background-color: #f4f4f4;
    }

    .duty-btn {
        width: 45%;
        line-height: 36px;
        color: #fff;
        font-size: 14px;
        border-radius: 18px;
        margin: 3% auto;
        background-color: #3e8ffd;
        text-align: center;
    }

    .mine-tab-li {
        padding-left: 13px;
    }

    .border-bottom-mine {
        border-bottom: 1px solid rgba(225, 225, 225, 0.5);
        margin-left: 60px;
        margin-right: 20px;
    }

    .border-bottom-mine2 {
        border-bottom: 1px solid rgba(225, 225, 225, 0.5);
        margin-left: 20px;
        margin-right: 20px;
    }

    .kdla-slog {
        color: #3e8ffd !important;
        font-size: 12px !important;
    }

    .mine_msg_div {
        width: 80%;
        padding-left: 14px;
        height: 100%;
    }

    .mine_role {
        font-size: 14px;
        margin: 0 0;
        padding-top: 3px;
        color: #999;
    }

    .myicon_mine {
        border-radius: 60px;
        width: 60px;
        height: 60px;
    }

    .mine-list a:after {
        height: 0px !important;
    }

    .mine-list .item-inner:after {
        height: 0px !important;
    }

    .status {
        margin-right: 5px;
    }

    .status-coclo {
        color: #0096ef;
    }

    .code-container {
        text-align: center;
        font-size: 15px;
        width: 100%;
        height: 140px;
        color: #999;
    }

    .phone-code {
        height: 110px;
        margin: 5px auto;
    }

    .versions_class {
        width: 100%;
        color: #999;
        margin-bottom: 2%;
    }

    .phone-code-text {
        font-size: 13px;
        width: 83px;
        margin: auto;
    }

    .mine-loginout {
        width: 100%;
        margin-top: 40px;
        margin-bottom: 40px;
        font-size: 14px;
        text-decoration: underline;
        line-height: 35px;
        display: block;
        text-align: center;
        color: #2471CA;
    }

    .focus-permiss_mine {
        display: none;
    }
</style>